package com.kazarus.examplx00002;

import android.app.Activity;
import android.app.AlertDialog; 
import android.content.Context;  
import android.content.DialogInterface;  
import android.os.Bundle;
import android.widget.Button;
import android.widget.Toast;
import android.view.View;  
import android.view.View.OnClickListener;
import android.view.LayoutInflater;  
import android.widget.EditText;  



public class examplx00002 extends Activity 
{
	Button Btnx_A;
	Button Btnx_B;
	Button Btnx_C;
	Button Btnx_D;
    /** Called when the activity is first created. */
    //@Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
        Btnx_A =(Button) this.findViewById(R.id.Btnx_A);
        Btnx_A.setOnClickListener(new OnBtnxAClickEvent());
        
        Btnx_B =(Button) this.findViewById(R.id.Btnx_B);
        Btnx_B.setOnClickListener(new OnBtnxBClickEvent());
        
        Btnx_C =(Button) this.findViewById(R.id.Btnx_C);
        Btnx_C.setOnClickListener(new OnBtnxCClickEvent());
        
        Btnx_D =(Button) this.findViewById(R.id.Btnx_D);
        Btnx_D.setOnClickListener(new OnBtnxDClickEvent());
        
    }
    
    class OnBtnxAClickEvent implements OnClickListener
    {
        //@Override  
        public void onClick(View v) 
        {  
             
            //Toast.makeText(examplx00002.this, "you click me by class OnBtnxAddxClickEvent ", Toast.LENGTH_SHORT).show();
        	showDialog(examplx00002.this);
        }     	
    }
    
    class OnBtnxBClickEvent implements OnClickListener
    {
    	//@Override
    	public void onClick (View v)
    	{
    		showDialog_Layout(examplx00002.this);
    	}
    	
    }
    
    class OnBtnxCClickEvent implements OnClickListener
    {
    	public void onClick (View v)
    	{
    		if (v==Btnx_A)
    		{
    			showDialog(examplx00002.this);
    		} else
    		if (v==Btnx_B)
    		{
    			showDialog_Layout(examplx00002.this);
    		}
    		
    	}
    }
    
    class OnBtnxDClickEvent implements OnClickListener
    {
    	public void onClick(View c)
    	{
    		AlertDialog.Builder builder = new AlertDialog.Builder(examplx00002.this);
    		builder.setTitle("some titile");
    		builder.setMessage("today is android day.");
    		builder.show();
    	}
    }
    
    private void showDialog(Context context) {  
        AlertDialog.Builder builder = new AlertDialog.Builder(context);  
        builder.setIcon(R.drawable.icon);  
        builder.setTitle("Title");  
        builder.setMessage("Message");  
        builder.setPositiveButton("Button1",  
                new DialogInterface.OnClickListener() {  
                    public void onClick(DialogInterface dialog, int whichButton) {  
                        setTitle("you clicked button1");  
                    }  
                });  
        builder.setNeutralButton("Button2",  
                new DialogInterface.OnClickListener() {  
                    public void onClick(DialogInterface dialog, int whichButton) {  
                        setTitle("you clicked button2");  
                    }  
                });  
        builder.setNegativeButton("Button3",  
                new DialogInterface.OnClickListener() {  
                    public void onClick(DialogInterface dialog, int whichButton) {  
                        setTitle("you clicked button3");  
                    }  
                });  
        builder.show();  
    }     
    
    //show LayoutAlertDialog  
    private void showDialog_Layout(Context context) {  
        LayoutInflater inflater = LayoutInflater.from(this);  
        final View textEntryView = inflater.inflate(  
                R.layout.dialoglayout, null);  
        final EditText edtInput=(EditText)textEntryView.findViewById(R.id.edtInput);  
        final AlertDialog.Builder builder = new AlertDialog.Builder(context);  
        builder.setCancelable(false);  
        builder.setIcon(R.drawable.icon);  
        builder.setTitle("Title");  
        builder.setView(textEntryView);  
        builder.setPositiveButton("postiviebutton",  
                new DialogInterface.OnClickListener() {  
                    public void onClick(DialogInterface dialog, int whichButton) {  
                        setTitle(edtInput.getText());  
                    }  
                });  
        builder.setNegativeButton("negativebuuton",  
                new DialogInterface.OnClickListener() {  
                    public void onClick(DialogInterface dialog, int whichButton) {  
                        setTitle("");  
                    }  
                });  
        builder.show();  
    }     
}